﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using CoreDemo.IServices;
using CoreDemo.Services;
using Microsoft.OpenApi.Models;
using com.passit.pai.core.net.dto.ko;
using MediatR;
using System.Reflection;

namespace CoreDemo
{
    public class Startup
    {
        public const string ApiName = "lalala";
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<ISingletonDemo, SingletonDemo>();
            services.AddScoped<IScopedDemo, ScopedDemo>();
            services.AddTransient<ITransientDemo, TransientDemo>();
            services.AddMvc();
            services.AddMediatR(Assembly.GetExecutingAssembly());
            services.AddSwaggerGen((c) =>
            {
                c.SwaggerDoc("V1", new OpenApiInfo
                {
                    Version = "V1",
                    Title = $"{ApiName} 接口文档——Netcore 3.0",
                    Description = $"{ApiName} HTTP API V1",
                    Contact = new OpenApiContact { Name = ApiName, Email = "357890853@qq.com", Url = new Uri("https://www.baidu.com") },
                    License = new OpenApiLicense { Name = ApiName, Url = new Uri("https://www.baidu.com") }
                });

                c.OrderActionsBy(o => o.RelativePath);
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseSwagger().UseSwaggerUI((options) =>
            {
                options.SwaggerEndpoint("/swagger/V1/swagger.json", "demo V1");
                options.RoutePrefix = "swagger";
            });
            
            app.UseMvc();


        }
    }
}
